package com.xm.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/validate.do")
public class ValidateCodeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、获取前台传送过来的code
        String code = request.getParameter("code");
        //2、获取后台随机产生验证码
        String _code = (String) request.getSession().getAttribute("_code");
        //3、对比是否一致
        if (_code.equals(code)){
            //验证码输入正确
            response.getWriter().print("success...");
        }else {
            //验证码输入错误
            response.getWriter().print("fail...");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
